package com.hl.web;

import com.github.pagehelper.PageInfo;
import com.hl.pojo.Expertiseareas;
import com.hl.service.FieldService;
import com.hl.util.GeneralResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/field")
@CrossOrigin
public class FieldController {
    @Resource
    private FieldService fieldService;
//    搜索所有擅长领域，分页
    @RequestMapping("/getFieldList")
    public GeneralResult getFieldList(Integer pageNum,Integer pageSize){
        List<PageInfo> list = new ArrayList<>();
        PageInfo<Expertiseareas> fieldList = fieldService.getFieldList(pageNum,pageSize);
        list.add(fieldList);
        return GeneralResult.success(list);
    }
//    根据领域名模糊查询
    @RequestMapping("/likeGetByName")
    public GeneralResult likeGetByName(@RequestBody Map<String,String> map){
        String areaName = map.get("areaName");
        List<Expertiseareas> list = fieldService.likeGetByName(areaName);
        return GeneralResult.success(list);
    }
//    新增领域
    @RequestMapping("/addField")
    public GeneralResult addField(@RequestBody Expertiseareas expertiseareas){
        String s = fieldService.addField(expertiseareas);
        return GeneralResult.success(s);
    }
//    根据id删除
    @RequestMapping("/deleteField")
    public GeneralResult deleteField(@RequestBody Map<String,Integer> map){
        Integer id = map.get("id");
        System.out.println(id);
        String s = fieldService.deleteField(id);
        return GeneralResult.success(s);
    }
    @RequestMapping("/updateField")
    public GeneralResult updateField(@RequestBody Expertiseareas expertiseareas){
        String s = fieldService.updateField(expertiseareas);
        return GeneralResult.success(s);
    }
}
